﻿using System;
using AnyCAD.Foundation;

namespace Rapid.Sketch.Plugin.Model
{
    public class SectionBarModel : ElementSchema
    {
        // 自定义的属性：double, int, bool, string
        public static double InnerRadius = 100;
        public static double Thickness = 10;
        public static double Length = 1000;

        public SectionBarModel()
            :base(nameof(SectionBarModel))
        {
            SetIcon("/Rapid.Common.Res;component/Image/SectionBar.png");
        }

        // 创建存储数据的类型
        public override Element OnCreateInstance()
        {
            return new ShapeInstance();
        }

        //自定义属性变化，更新几何形状
        public override bool OnParameterChanged(Document doc, Element instance, ParameterDict parameters)
        {
            ParseParameters(parameters, null);
            var shape = CreateShape();
            if (shape == null)
                return false;

            var shapeElement = ShapeInstance.Cast(instance);
            if (shapeElement == null)
                return false;
            shapeElement.SetShape(shape);
            return true;
        }

        // 根据参数创建几何，也可以从文件加载
        public TopoShape CreateShape()
        {
            return ShapeBuilder.MakeTube(GP.Origin(), GP.DZ(), InnerRadius, Thickness, Length);
        }
    }
}
